using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Effect : MonoBehaviour
{
    public List<EffectInfo> Effects;
    float time = 0;
    public virtual void Awake()
    {
        Effects = new List<EffectInfo>();
    }

    void FixedUpdate()
    {
        time += Time.deltaTime;
        if(Effects!=null)
        {
            List<EffectInfo> removeEffects=new List<EffectInfo>();
            foreach (var effect in Effects)
            {
                if (effect.InitTime < time)
                {
                    GameMgr.Get<IEffectManager>().InstantiateEffect(effect.EffectName, transform.position, effect.Angle + transform.eulerAngles.z);
                    removeEffects.Add(effect);
                }
            }
            foreach(var effect in removeEffects)
            {
                if(effect!=null)
                {
                    Effects.Remove(effect);
                }
            }
            removeEffects.Clear();

            if(Effects.Count==0)
            {
                DestroyImmediate(gameObject);
            }
        }
    }
}

public class EffectInfo
{
    public string EffectName;
    public float InitTime;
    public float Angle;
    public EffectInfo(string name,float time,float angle = 0)
    {
        EffectName = name;
        InitTime = time;
        Angle = angle;
    }
}
